﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;

namespace Demo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;//使线程可以调用窗体控件
        }
        int x = 12;//定义图标初始横坐标位置
        void Roll()
        {
            while (x <= 260)// 设置循环条件
            {                       
                // 将标签的横坐标用变量表示
                pictureBox1.Location = new Point(x, 12);
                Thread.Sleep(500);// 使线程休眠500毫秒
                x += 4;// 使横坐标每次增加4
                if (x >= 260)
                {
                    x = 12;// 当图标到达标签的最右边时，使其回到标签最左边
                }
            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            Thread th = new Thread(new ThreadStart(Roll));//创建线程对象
            th.Start();//启动线程
        }
    }
}
